<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/include/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title><%=system_name%> - 通讯录管理</title>
	<%@include file="/WEB-INF/jsp/include/meta.jsp"%>
	
	<link href="<%=basePath%>css/public.css" rel="stylesheet" type="text/css">
	<link href="<%=basePath%>css/index.css" rel="stylesheet" type="text/css">
	<link href="<%=basePath%>css/common.css" rel="stylesheet" type="text/css" />
	<script src="<%=basePath%>js/common.js" type="text/javascript"></script>
	<script type="text/javascript" src="js/pagebar.js"></script>
	<script type="text/javascript" src="fram/engine.js" ></script>
	<script type="text/javascript" src="fram/util.js" ></script>
	<script type="text/javascript" src="fram/interface/addressBookService.js"></script>
</head>

<body oncontextmenu='return false'>

<%@include file="/WEB-INF/jsp/include/head.jsp"%>

<div class="wrap100">

	<!--full begin-->
    <div class="full">
    
    		<!--产品详细信息 begin-->	
    		<div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>联系人快速搜索</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>                
            </div>
            <div id="clear"></div>
            
            <div class="rightBorder">
            
            <form action="<%=basePath%>trade/addressBookList" method="GET">
            <table width="75%" border="0" align="center" cellpadding="3" cellspacing="0">
              <tr>
                <td>公司：                </td>
                <td><input size="25" class="input" type="text" name="companyName" id="companyName" value="${searchCond.companyName}"/></td>
                <td>联系人：</td>
                <td><input size="25" class="input" type="text" name="userName" id="userName" value="${searchCond.userName}"/></td>
                <td><input type="submit" style="background:url(images/search.gif);width:92px;height:25px;border:0;margin:0;" value="" /></td>
              </tr>
            </table>
            </form>
      </div>
      
            <div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>联系人列表</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>
            </div>
            <div id="clear"></div>
            
            <div class="rightPropertyList">
            	<div class="title1">
                <table width="100%"  border="0" cellpadding="1" cellspacing="1" bgcolor="#dfe5e9">
                  <tr>
                    <th width="2%"  align="center"><input type="checkbox" name="allSelectId" id="allSelectId" onclick="judgmentChecjBox('allSelectId','id')" /></th>
                    <th width="10%">公司名称</th>
                    <th width="8%" >联系人</th>
                    <th width="8%" >固话</th>
                    <th width="8%" >传真</th>
                    <th width="8%" >手机</th>
                    <th width="8%" >QQ</th>
                    <th width="10%" >MSN</th>
                    <th width="10%" >Email</th>
                    <th width="12%" >地址</th>
                    <th width="16%" >备注</th>
                  </tr>
                  <!-- 
                </table>
            </div>
                <div class="list2">
                  <table width="100%"  border="0" cellpadding="1" cellspacing="1" bgcolor="#dfe5e9">
                   -->
                  	<c:forEach var="user" items="${addressBookList}">
                    <tr>
                      <td width="2%"  align="center"><input type="checkbox" value="${user.id}" name="id" /></td>
                      <td width="10%"><label title="${user.companyName}">${fne:subStringB(user.companyName,'...',0,8)}</label></td>
                      <td width="8%" >${user.userName}</td>
                      <td width="8%" >${user.telphone}</td>
                      <td width="8%" >${user.fax}</td>
                      <td width="8%" >${user.mobile}</td>
                      <td width="8%" >${user.qq}</td>
                      <td width="10%" >${user.msn}</td>
                      <td width="10%" >${user.email}</td>
                      <td width="12%" ><label title="${user.address}">${fne:subStringB(user.address,'...',0,8)}</label></td>
                      <td width="16%" ><label title="${user.detail}">${fne:subStringB(user.detail,'...',0,12)}</label></td>
                    </tr>
                    </c:forEach>
					<c:if test="${empty addressBookList}"><tr><td colspan="8" style="text-align:center">没有相关记录！</td></tr></c:if>
                    
                  </table>
                </div>
            </div>

            <!--统计 end-->
            <div class="total">
                <div class="fl Statistics">总数：<strong>${searchStat.totalCount}</strong> 条
                <script type="text/javascript">
				var pageControl = new wpagebar('pageControl');
				pageControl.argName = "pageIndex";
				pageControl.pageCount = ${searchStat.pageCount};
				pageControl.load();
				</script> 
                </div>
                
                <div class="fr Operating">                
                    <ul>
                    	<!-- <li><input name="复 制" type="button" class="button" value="复 制" /></li> -->
                        <li><input name="添 加" type="button" class="button" value="添 加" onclick="addAddressBook()"/></li>
                        <li><input name="修 改" type="button" class="button" value="修 改" onclick="editAddressBooks()"/></li>
                        <li><input name="删 除" type="button" class="button" value="删 除" onclick="delsellMultiple()"/></li>
                        <li><input name="生成EXL表" type="button" class="button" value="导出EXCEL" onclick="exportExcel()"/></li>
                    </ul>                
                
                </div>
            </div>
    
    </div>
    <div id="win_temp" style="display:none">
	<div id="winCon_1">
	<form>
	<table class="tabView" style="margin-top:5px">
		<tr><th width="100">姓名：</th><td><input type="text" name="userName0" id="userName0" value=""/>
			<input type="hidden" name="userId0" id="userId0" />			
			<input type="hidden" name="userId" id="userId" value="${userId}"/>
			</td>
			<th width="80">性别：</th><td><input type="radio" name="sex0" checked="checked"/>男 <input type="radio" name="sex0"/>女 </td>
		</tr>
		<tr><th>公司名称：</th><td colspan="3"><input type="text" name="companyName0" id="companyName0" size=60 /></td></tr>
		<tr><th>联系电话：</th><td><input type="text" name="telphone0" id="telphone0" value=""/></td>
			<th>联系传真：</th><td><input type="text" name="fax0" id="fax0" value=""/></td></tr>
		<tr><th>QQ：</th><td><input type="text" name="qq0" id="qq0" value=""/></td>
			<th>MSN：</th><td><input type="text" name="msn0" id="msn0" value=""/></td></tr>
		<tr>
			<th>Email：</th><td><input type="text" name="email0" id="email0"/></td>
			<th>手机：</th><td><input type="text" name="mobile0" id="mobile0" > </td></tr>
		<tr><th>地址：</th><td colspan="3"><input type="text" name="address0" id="address0" size=60></td></tr>
		<tr><th>备注：</th><td><textarea name="detail0" id="detail0" rows="3" cols="50"></textarea> </td></tr>
		<tr><td colspan="2" style="text-align:right;height:"><input type="button" value=" 提 交 " class="btn1" onclick="submitAddressBook()"/></td>
			<td colspan="2" style="text-align:left;height:"><input type="reset" value=" 重置 " class="btn1" value="reset"/></td>
		</tr>
	</table>
	</form>
	</div>
	</div>  
    <script src="<%=basePath%>js/win.js" type="text/javascript"></script>
    
</div>

<%@include file="/WEB-INF/jsp/include/bottom.jsp"%>

<script  type="text/javascript">
function addAddressBook(){
	WIN.show('<font size=5>添加通讯录信息</font>',$('winCon_1'),{width:600,height:380});
}

function delsellMultiple(){			
	var objs = document.getElementsByName("id");
	var ids='';	
	for(var i=0;i<objs.length;i++){
		if(objs[i].checked){
			ids+=objs[i].value+",";
		}
	}
	if(ids==''){
		alert("请先选择要操作的信息");
		return ;
	}
	ids = ids.substring(0,ids.length - 1);
	
	if(confirm("您确定要删除?")){
		if(ids == ""){
			alert("请先选择要删除的信息！");
			return false;
		}else{
			addressBookService.deleteAddressBooks(ids,{
				callback:function(f){alert("删除成功");reload();},
				exceptionHandler:function(message){alert("删除失败，请重试");},
				errorHander:function(err){}
			})
		}
	}
}
function exportExcel(){			
	var ids = getSelectedCheckBoxValues('id');
	if(ids == "")
		alert("请先选择要导出的信息！");
	else {
		window.open("<%=basePath%>trade/exportExcel?t=1&ids="+ids);
	}
}
function editAddressBooks(){
	var objs = document.getElementsByName("id");	
	var ids=0;
	var vas='';
	for(var i=0;i<objs.length;i++){
		if(objs[i].checked){
			ids++;
			vas=objs[i].value;			
		}
	}
	if(ids!=1){
		alert("请选择一条且只能选择一条信息进行编辑！");
		return ;
	}	
	if(vas==''){
		alert("请先选择要操作的信息");
		return ;
	}else{
		editAddressBook(vas);
	}	
}
function editAddressBook(id){
	WIN.show('<font size=5>修改通讯录信息</font>',$('winCon_1'),{width:600,height:380});
	addressBookService.getAddressBookById(id,function(data){
		$('userId').value=data.user.id;
		$('userId0').value=data.id;
		$('userName0').value=data.userName;
		$('companyName0').value=data.companyName;
		if(data.sex){$N('sex0')[0].checked=true;}else{$N('sex0')[1].checked=true;}
		$('telphone0').value=data.telphone;
		$('fax0').value=data.fax;
		$('mobile0').value=data.mobile;
		$('qq0').value=data.qq;
		$('msn0').value=data.msn;
		$('email0').value=data.email;
		$('address0').value=data.address;
		$('detail0').value=data.detail;				
	})
}
function delAddressBook(id){
	if(confirm("删除联系人，确定删除 ？")){
		WIN.showpg();
		addressBookService.deleteAddressBook(id,{
			callback:function(f){WIN.closepg();alert("删除成功");reload();},
			exceptionHandler:function(message){WIN.closepg();alert("删除失败，请重试");},
			errorHander:function(err){}
		})
	}
}

function submitAddressBook(){	
	var user={
		user:       {id:$('userId').value},
		id	:		$('userId0').value,
		userName:	$('userName0').value,
		companyName:$('companyName0').value,
		sex:		$N('sex0')[0].checked,
		telphone:	$('telphone0').value,
		fax:	    $('fax0').value,
		mobile:     $('mobile0').value,
		email:	    $('email0').value,
		address:	$('address0').value,
		qq:	        $('qq0').value,
		msn:	    $('msn0').value,
		detail:   	$('detail0').value
	}
	
	if(''==user.userName){
		alert('名称不能为空');return;
	}else{
		submit(user);
	}
}
function submit(user){
	WIN.close();
	WIN.showpg();
	addressBookService.editAddressBook(user,{
		callback:function(f){WIN.closepg();alert("操作成功");reload();},
		exceptionHandler:function(message){WIN.closepg();alert(message);alert("操作失败，请重试");},
		errorHander:function(err){}
	})
}

</script>
</body>
</html>
